//
//  XHMainViewController.swift
//  XHWeiboSwift
//
//  Created by mac on 17/1/16.
//  Copyright © 2017年 mac.gu. All rights reserved.
//

import UIKit

class XHMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        //自定义taBar
        let taBbar = XHTabBar()
        
//        setValuesForKeys(["tabBar":tabbar])
        
        setValue(taBbar, forKey: "tabBar")
        
        taBbar.closeure = {
            
            print("加号按钮的点击事件")
        }
        
        
        
        
        
        
        
        
        
        
        addChildViewController(XHHomeViewController(), title: "首页", imageNormalName: "tabbar_home")
        addChildViewController(XHMessageViewController(), title: "信息", imageNormalName: "tabbar_message_center")
        addChildViewController(XHDiscoverViewController(), title: "发现", imageNormalName: "tabbar_discover")
        addChildViewController(XHProfileViewController(), title: "我", imageNormalName: "tabbar_profile")
        
        
     
        

    }

    func addChildViewController(_ childController: UIViewController , title: String ,imageNormalName:String) {
    
        //设置正常图片
        childController.tabBarItem.image = UIImage(named: imageNormalName)?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        
        //设置选中图片
        
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageNormalName)_selected")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        //设置title
        childController.title = title
        
        //设置title颜色
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orange], for: UIControlState.selected)
        
        //设置标签控制器的根控制器
        
        addChildViewController(UINavigationController(rootViewController: childController))
        
        
    }

}
